import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/main.vue'
import Home from '../views/Home.vue'
// import article from '../views/content/article.vue'
import Appointment from '../views/consult/Appointment.vue'
import UserMark from '../views/consult/UserMark.vue'
import ConsultReply from '../views/consult/ConsultReply.vue'


Vue.use(VueRouter)

const routes = [{
		path: '/',
		redirect: '/login'
	},
	{
		path: '/login',
		name: 'login',
		component: Login
	},
	{
		path: '/main',
		component: Main,
		children: [{
				path: '/',
				redirect: '/home'
			},
			{
				path: '/home',
				component: Home
			},
			{
				path: '/article',
				name: 'article',
				component: () => import('../views/content/article.vue')
			},
			{
				path: '/FM',
				name: 'FM',
				component: () => import('../views/content/FM.vue')
			},
			{
				path: '/free',
				name: 'free',
				component: () => import('../views/content/free.vue')
			},
			{
				path: '/SystemUser',
				name: 'SystemUser',
				component: () => import('../views/system/SystemUser.vue')
			},
			{
				path: '/User',
				name: 'User',
				component: () => import('../views/system/User.vue')
			},
			{
				path: '/Publicity',
				name: 'Publicity',
				component: () => import('../views/system/Publicity.vue')
			},
			{
				path: '/Appointment',
				name: 'Appointment',
				component: () => import('../views/consult/Appointment.vue')
			},
			{
				path: '/coursetype',
				name: 'coursetype',
				component: () => import('../views/course/CourseType.vue')
			},
			{
				path: '/question',
				name: 'question',
				component: () => import('../views/PsychologicalQA/question.vue')
			},
			{
				path: '/reply',
				name: 'reply',
				component: () => import('../views/PsychologicalQA/reply.vue')
			},
			{
				path: '/coursemark',
				name: 'coursemark',
				component: () => import('../views/course/CourseMark.vue')
			},
			{
				path: '/UserMark',
				name: 'UserMark',
				component: () => import('../views/consult/UserMark.vue')
			},
			{
				path: '/ConsultReply',
				name: 'ConsultReply',
				component: () => import('../views/consult/ConsultReply.vue')
			},
			{
				path: '/Company',
				name: 'Company',
				component: () => import('../views/system/company.vue')
			},
			{
				path: '/psychologicalKnowledge',
				name: 'psychologicalKnowledge',
				component: () => import('../views/content/PsychologicalKnowledge.vue')
			},
			{
				path: '/heartmark',
				name: 'heartmark',
				component: () => import('../views/content/Heartmark.vue')
			},
			{
				path: '/consult',
				component: () => import('../views/Consultants/Consult.vue')
			},
			{
				path: '/consultlevel',
				component: () => import('../views/Consultants/ConsultLevel.vue')
			},
			{
				path: '/specialty',
				component: () => import('../views/Consultants/Specialty.vue')
			},
			{
				path: '/chargetype',
				component: () => import('../views/Consultants/ChargeType.vue')
			},
			{
				path: '/charge',
				component: () => import('../views/Consultants/Charge.vue')
			},
			{
				path: '/articleType',
				name: 'articleType',
				component: () => import('../views/content/ArticleType.vue')
			},
			{
				path: '/course',
				name: 'course',
				component: () => import('../views/course/Course.vue')
			}
		]
	}
]

const router = new VueRouter({
	routes
})
router.beforeEach((to, from, next) => {
	if (to.path === '/login') {
		return next();
	}
	let username = sessionStorage.getItem('username');
	if (!username) {
		return next('/login')
	}
	next();
})






router.beforeEach((to, from, next) => {
	if (to.path === '/login') {
		return next();
	}
	let username = sessionStorage.getItem('username');
	if (!username) {
		return next('/login');
	}
	next();
})





export default router